const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const mysqlConnect = require('./mysqlConfig');
const userRouter = require('./user');

const app = express();
app.use(cookieParser());
app.use(bodyParser.json());
app.use('/user', userRouter);


app.get('/', (req, res) => {
    res.send("<h1>Hello,World!</h1>");
});

app.get('/data', function (req, res) {
    let sqlQuery = "select userID,userName,phone,type from users";
    mysqlConnect.sql(sqlQuery, (err, rows, fields) => {
        if (err) {
            console.log(err);
            return;
        }
        res.json(rows);
        console.log(rows);
    });
});

app.listen(9093, () => {
    console.log("服务器开始运行在9093端口");
});